#include "zf_common_headfile.h"

uint8_t mt9v03x_image[MT9V03X_H][MT9V03X_W];
uint8_t mt9v03x_finish_flag;

cv::Mat colorImage(ROW,COL, CV_8UC3);
//OpenCV实现画线
void OpenCV_DrawLine(uint8_t (* ipts)[2],uint8_t * ipts_num,uint8_t blue,uint8_t green,uint8_t red)
{
    for(uint8_t i = 0; i < *ipts_num; i++)
    {
        cv::circle(colorImage, cv::Point(ipts[i][0], ipts[i][1]), 0.5, cv::Scalar(blue, green,red), -1);  // 半径为3的红色实心圆
    }
}


//OpCV图像转成数组
void OpenCV_Transfer(uint8_t mt9v03x_image[][MT9V03X_W], const cv::Mat& sourceImage) {  

    // 将源图像的每个像素复制到目标数组中  
    for (int i = 0; i < sourceImage.rows; ++i) {  
        for (int j = 0; j < sourceImage.cols; ++j) {  
            mt9v03x_image[i][j] = sourceImage.at<uint8_t>(i, j);  
        }  
    }  
}

/**
 * 从灰度图转到opencv格式的mat图
 */
void OpenCV_Inverse(void)//将处理后的图像经过OpenCV逆转
{
    // 将数组数据复制到图像的每个通道
    for (int i = 0; i < colorImage.rows; ++i)
    {
        for (int j = 0; j < colorImage.cols; ++j)
        {
            colorImage.at<cv::Vec3b>(i, j) = cv::Vec3b(Gray_Image[i][j],Gray_Image[i][j],Gray_Image[i][j]);
        }
    }

for (int ry = ROW_Start; ry >= ROW_Start-iptsr_num; ry--)
{
        cv::circle(colorImage,cv::Point(iptsr[ry],ry), 0.5,cv::Scalar(0,0,255), -1);
}

for (int ry = ROW_Start; ry >= ROW_Start-iptsL_num; ry--)
{
        cv::circle(colorImage,cv::Point(iptsL[ry],ry), 0.5,cv::Scalar(255,0,0), -1);
}

for (int ry = ROW_Start; ry >= ROW_Start-rpts_num; ry--)
{
        cv::circle(colorImage,cv::Point(rpts[ry],ry), 0.5,cv::Scalar(0,255,0), -1);
}

// for (int i = 0; i < rpts_num; ++i)
// {
//     if(i>=Image_DataStruct.begin_err && i<=(Image_DataStruct.begin_err+11))
//     {
//         cv::circle(colorImage, cv::Point(rpts[i],rpts[i][1]), 0.5, cv::Scalar(255,0,0), -1);
//     }
//     else
//     {
//         cv::circle(colorImage, cv::Point(rpts[i][0],rpts[i][1]), 0.5, cv::Scalar(0,255,0), -1);
//     }
// }

}

void draw_maze(uint8_t choice)
{
    if(choice ==0)
    {
        for(uint8_t i = 0; i < ipts0_num; i++)
        {
            cv::circle(colorImage, cv::Point(ipts0[i][0], ipts0[i][1]), 0.5, cv::Scalar(255, 0,255), -1);  // 半径为3的红色实心圆
        }

    }
    else if(choice==1)
    {
        for(uint8_t i = 0; i < ipts1_num; i++)
        {
            cv::circle(colorImage, cv::Point(ipts1[i][0], ipts1[i][1]), 0.5, cv::Scalar(165, 42,42), -1);  // 半径为3的红色实心圆
        }
    }

}

